<?php
/**
 * Created by PhpStorm.
 * User: hetu
 * Date: 2018/5/14
 * Time: 9:55
 */

use \yii\helpers\Url;
use \yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\widgets\Pjax ;

$id = Yii::$app->request->get("id") ;
$status = [
       '1' => '可用', '0' => '停用'
    ]
?>
<form id="edit-contral-form" class="form-horizontal" method="post">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel"><?= empty($id)?"添加":"编辑";?>系统参数</h4>
    </div>
    <div style="border-bottom: 1px solid #e5e5e5"></div>
    <div class="modal-body">
        <div class="box-body">
            <div class="form-group">
                <label class="col-sm-4 control-label">标识：</label>
                <div class="input-group col-sm-4 field-registerform-phone required" style="padding-right: 15px;padding-left: 15px;">
                    <input class="form-control" type="text" id="ContralSetForm-unique_mark" name="ContralSetForm[unique_mark]" value="<?= $model->unique_mark ?>">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">参数名：</label>
                <div class="input-group col-sm-4 field-registerform-phone required" style="padding-right: 15px;padding-left: 15px;">
                    <input class="form-control" type="text" id="ContralSetForm-name" name="ContralSetForm[name]" value="<?= $model->name ?>">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">控制值：</label>
                <div class="input-group col-sm-4 field-registerform-phone required" style="padding-right: 15px;padding-left: 15px;">
                    <textarea class="form-control" type="text" id="ContralSetForm-value" name="ContralSetForm[value]"  rows="10"><?= $model->value ?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">描述：</label>
                <div class="input-group col-sm-4 field-registerform-phone required" style="padding-right: 15px;padding-left: 15px;">
                    <input class="form-control" type="text" id="ContralSetForm-description" name="ContralSetForm[description]" value="<?= $model->description ?>">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">备注：</label>
                <div class="input-group col-sm-4 field-registerform-phone required" style="padding-right: 15px;padding-left: 15px;">
                    <input class="form-control" type="text" id="ContralSetForm-remark" name="ContralSetForm[remark]" value="<?= $model->remark ?>">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">参数1：</label>
                <div class="input-group col-sm-4 field-registerform-phone required" style="padding-right: 15px;padding-left: 15px;">
                    <input class="form-control" type="text" id="ContralSetForm-parameter" name="ContralSetForm[parameter]" value="<?= $model->parameter ?>">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" >状态：</label>
                <div class="input-group col-sm-4 field-registerform-phone required" style="padding-right: 15px;padding-left: 15px;">
                    <select name="ContralSetForm[status]" class="form-control">
                        <?php foreach ($status as $key=>$item):?>
                            <?php if ($model->status == $key):?>
                                <option value="<?= $key ?>" selected><?= $item ?></option>
                            <?php else:?>
                                <option value="<?= $key ?>"><?= $item ?></option>
                            <?php endif ?>
                        <?php endforeach ?>
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <?= Html::hiddenInput('_csrf-backend',\Yii::$app->getRequest()->csrfToken) ?>
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary" id="edit-contral-ajax-submit">保存</button>
        <input type="hidden" id="get-id" class="form-control" name="get-id" data-id="<?= $id ?>">
    </div>
</form>
<script>
    $('#edit-contral-ajax-submit').click(function () {
        var data = $('#edit-contral-form').serialize();
        var id = $('#get-id').data('id');
        sendAjax('<?= Url::toRoute('edit-contral') ?>' + '?id=' + id, data, $(this));
    });
</script>